<template>
  <div v-if="!MSDSDetailShow" class="Tanks">
    <div class="Tanks_Head">
      <span>{{ obj.gtmc }}</span>
      <!-- <span>X</span> -->
    </div>
    <!-- 仓库页面 -->
    <div v-if="props.isTank" class="Tanks-top tanks2 flex-center relative">
      <div
        class="text-white text-[20px] font-bold"
        style="
          width: 170px;
          height: 80px;
          background: rgba(0, 0, 0, 0.6);
          border: 1px solid #00ffe0;
          padding: 15px;
          position: absolute;
          right: 20px;
          top: 20px;
        "
      >
        <div class="text-[#00FFD8]">面积</div>
        <div class="text-[30px]">5613 ㎡</div>
      </div>
      <img src="@/assets/image/buildingModel.png" class="w-[188px] h-[145px] mt-[70px]" alt="" />
    </div>
    <!-- 危化车页面 -->
    <div v-else-if="!props.isTank" class="Tanks-top">
      <div ref="inputREF">
        <input
          v-model="inputVal"
          type="text"
          placeholder="请输入化危品名称"
          @click="handleSearch"
        />
        <button @click="searchMSDS">MSDS查询</button>
      </div>
      <!-- MSDS查询 -->
      <div v-show="flag" class="MSDSBox">
        <table border="1" width="100%">
          <!--border：表格边框，width：表格宽度-->
          <thead>
            <tr>
              <!--th标签：表格头，内容居中，加粗显示-->
              <th>序号</th>
              <th>中文名称</th>
              <th>英文名称</th>
              <th>CAS.NO</th>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="(item, index) in tableData"
              :key="index"
              class="hover:bg-dark"
              align="center"
              @click="openMSDSDetail(item)"
            >
              <!--td标签：普通表格，内容左对齐-->
              <td class="index">{{ index + 1 }}</td>
              <td class="nameCH">{{ item.zwm }}</td>
              <td class="nameEN">{{ item.ywm }}</td>
              <td class="indexDES">{{ item.cas }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="flex" style="height: 90%; background: rgba(1, 10, 15, 0.5); padding: 10px">
        <div class="leftBox">
          <div
            style="
              width: 180px;
              height: 40px;
              border-bottom: 4px solid rgba(255, 51, 51, 0.4);
              background: rgba(255, 51, 51, 0.4);
              line-height: 40px;
              text-align: center;
              color: #fff;
              font-size: 20px;
              font-weight: bolder;
            "
          >
            一级重大危险源
          </div>
          <div class="left">
            <div>{{ obj.cglx.slice(0, 2) }}</div>

            <div class="box">
              <img src="@/assets/image/guanti.png" alt="" />
              <div class="centerText">{{ obj.sjyj }}m³</div>
            </div>
            <div class="leftText">H:{{ obj.cggd }}m</div>
            <div>L:{{ obj.cgzj }}m</div>
          </div>
        </div>
        <div class="rightBox">
          <div class="formItem">
            <div class="label">储罐型式</div>
            <div class="content">{{ obj.cgxs }}</div>
          </div>
          <div class="formItem">
            <div class="label">储罐类型</div>
            <div class="content">{{ obj.cglx }}</div>
          </div>
          <div class="formItem">
            <div class="label">保温层</div>
            <div class="content">{{ obj.ywbwc }}</div>
          </div>
          <div class="formItem">
            <div class="label">设计容积</div>
            <div class="content">{{ obj.sjyj }}m3</div>
          </div>
          <div class="formItem">
            <div class="label">设计储量</div>
            <div class="content">{{ obj.cgsjccnl }}T</div>
          </div>
          <div class="formItem">
            <div class="label">常规储量</div>
            <div class="content">{{ obj.cgcl }}MPa</div>
          </div>
          <div class="formItem">
            <div class="label">设计压力</div>
            <div class="content">{{ obj.cgsjyl }}T</div>
          </div>
          <div class="formItem">
            <div v-show="store.isBigLabel" class="btn activated" @click="openBigLabel">
              打开受灾部位标牌
            </div>
            <div v-show="!store.isBigLabel" class="btn" @click="openLittleLabel">关闭受灾部位</div>
          </div>
        </div>
      </div>
    </div>
    <div class="Tanks-center">
      <div class="Tanks-one-top">
        <div class="">
          <div class="title">存储介质</div>
          <div style="color: #fff; font-size: 22px; line-height: 60px">{{ obj.ccjz }}</div>
        </div>
        <div class="flex">
          <div v-for="(item, index) in obj.msdsXx.tbxx" :key="index" class="text-center mr-[10px]">
            <img :src="item.tbdz" style="display: ;inline-block" alt="" />
            <div class="text-white">{{ item.lx }}</div>
          </div>
        </div>
      </div>
      <div class="mt-[10px]" style="font-size: 18px; color: #fff">
        <div class="flex">
          <div class="title">危险特性丨</div>
          <div class="wxtxText">{{ obj.msdsXx.wxtx }}</div>
        </div>
        <div class="mt-4 flex">
          <div class="title">有害燃烧产物丨</div>
          <div class="yhrswText">{{ obj.msdsXx.yhrscw }}</div>
        </div>
      </div>
    </div>
    <div class="Tanks-bottom">
      <div style="font-size: 18px; color: #fff">
        <div class="m-2">灭火模型</div>
        <div class="flex justify-between items-center">
          <div>
            <div class="pjBox">
              <span>泡沫原液 丨</span>
              <span>{{ mxObj?.mhmxPmyy || 338 }} t</span>
            </div>
            <div class="pjBox">
              <span>用水储备 丨</span>
              <span>{{ mxObj?.mhmxYscb || 5314 }} t</span>
            </div>
          </div>
          <!-- 连接线 -->
          <div class="lineBox"></div>
          <div class="line1"></div>
          <div class="pjBox">
            <span>强度丨</span>
            <span>{{ mxObj?.mhmxQd || 9812.5 }} L/s</span>
          </div>
        </div>
      </div>
    </div>
    <div
      style="
        width: 460px;
        height: 100px;
        background: rgba(1, 10, 15, 0.5);
        font-size: 18px;
        color: #fff;
        padding: 5px;
      "
    >
      <div class="mb-[10px]">冷却模型</div>
      <div class="flex justify-between items-center relative">
        <div class="pjBox">
          <span>用水储备 丨</span>
          <span>{{ mxObj?.lqmxYscb || 5314 }} t</span>
        </div>
        <!-- 连接线 -->
        <div class="line2"></div>
        <div class="pjBox">
          <span>强度丨</span>
          <span>{{ mxObj?.lqmxQd || 9812 }}L/s</span>
        </div>
      </div>
    </div>
    <div
      style="width: 460px;height: 97px;background: rgba(1, 10, 15, 0.5);;font-size: 18px;18px;color:#fff;padding: 5px"
    >
      <div class="m-2">总攻模型</div>
      <div style="font-size: 18px">
        <div class="flex justify-between items-center flex-wrap">
          <div class="pjBox">
            <span>泡沫原液丨</span>
            <span>{{ mxObj?.zgmxPmyy || 338 }} t</span>
          </div>
          <div class="pjBox">
            <span>用水储备 丨</span>
            <span>{{ mxObj?.mhmxYscb || 5314 }} t</span>
          </div>
          <div class="pjBox mt-2">
            <span>供水强度丨</span>
            <span>{{ mxObj?.zgmxGsqd || 502 }} L/s</span>
          </div>
          <div class="pjBox mt-2">
            <span>灭火用时丨</span>
            <span> {{ mxObj?.zgmxMhys || 1 }} </span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <MSDSDetail
    v-if="MSDSDetailShow"
    :checked-chemicals-id="checkedChemicalsId"
    @changeDetailState="changeDetailState"
  >
  </MSDSDetail>
</template>
<script setup lang="ts">
import TankLabel from './TankLabel.vue'
import MSDSDetail from './MSDS/MSDSDetail.vue'
import { queryHgMsdsbInfoList } from '@/service'
import { replaceInfoWindow, removeAndAdd } from '@/utils'
import Sign from '@/components/common/Sign.vue'
import { useBusinessStore } from '@/store'
const store = useBusinessStore()
const props = defineProps({
  isTank: {
    type: Boolean,
    default: true,
  },
})
const obj: any = ref({
  gtid: '',
  gtmc: '',
  cgxs: '暂无',
  cglx: '暂无',
  ywbwc: '暂无',
  sjyj: '0',
  cgsjyl: '0',
  cgsjccnl: '0',
  cgcl: '0',
  cggd: '0',
  cgzj: '0',
  ccjz: '暂无',
  msdsXx: {
    wxtx: '暂无',
    tbxx: [],
    yhrscw: '暂无',
  },
})

watch(
  () => store.StorageTankInfo,
  (newVal, oldValue) => {
    obj.value = newVal
    console.log(obj.value)
  },
  { immediate: true }
)

const mxObj: any = ref({
  lqmxQd: '0',
  lqmxYscb: '0',
  mhmxPmyy: '0',
  mhmxQd: '0',
  mhmxYscb: '0',
  zgmxGsqd: '0',
  zgmxMhys: '0',
  zgmxPmyy: '0',
  zgmxYscb: '0',
})
const tabInfoObj: any = ref({})
// 点击小标牌查询的模型数据
watch(
  () => store.StorageMxxxInfo,
  (newVal, oldValue) => {
    mxObj.value = newVal
    // store.isBigLabel = true
  },
  { immediate: false }
)

watch(
  () => store.StorageTankInfoAttirbute,
  (newVal, oldValue) => {
    tabInfoObj.value = newVal
  },
  { immediate: true }
)
const qyId = ref('')
watch(
  () => store.zddwid,
  (newVal, oldValue) => {
    qyId.value = newVal
  },
  { immediate: true }
)
// 生成小标牌的数据

const openBigLabel = () => {
  // 小标牌隐藏
  // window.GOverlay.setVisibleByName(obj.value.gtid, false)
  replaceInfoWindow(obj.value.bzbh, TankLabel, obj.value, tabInfoObj.value, qyId.value)
  store.isBigLabel = false
}
const openLittleLabel = () => {
  console.log(tabInfoObj.value)

  // let data = store.StorageTankInfoAttirbute as any
  removeAndAdd(tabInfoObj.value.wzxx, Sign, tabInfoObj.value, { qyId: qyId.value })
  store.isBigLabel = true
}

// MSDS查询弹出框
const inputVal = ref('') // 输入框值
const flag = ref(false) // 控制输入框显隐
const inputREF = ref(null)
//  监听点击空白处关闭检索下拉栏
onClickOutside(inputREF, () => {
  flag.value = false
})

// const { focused } = useFocus(inputREF)
// watch(focused, (focused) => {
//   if (focused) {

//   } else {
//     flag.value = false
//   }
// })

const tableData: any = ref([])
// 点击输入框展示下拉框
const handleSearch = () => {
  flag.value = true
  queryHgMsdsbInfoList({ pageNo: 1, pageSize: 10 }).then((res: any) => {
    // console.log(res)
    tableData.value = res.records
  })
}
// 点击查询
const searchMSDS = () => {
  // flag.value = false
  queryHgMsdsbInfoList({ zwm: inputVal.value }).then((res: any) => {
    // console.log(res)
    tableData.value = res.records
  })
  // inputVal.value = ''
}
watch(
  () => inputVal.value,
  (newVal, oldVal) => {
    queryHgMsdsbInfoList({ zwm: inputVal.value }).then((res: any) => {
      // console.log(res)
      tableData.value = res.records
    })
  }
)
// const searchChange = () => {
//   queryHgMsdsbInfoList({ pageNo: 1, pageSize: 10 }).then((res: any) => {
//     console.log(res);
//     tableData.value = res.records
//   })
// }

const MSDSDetailShow = ref(false)
const checkedChemicalsId = ref()
// 点击数据跳转至msds详细页
const openMSDSDetail = (item: any) => {
  checkedChemicalsId.value = item.cas
  MSDSDetailShow.value = true
}
const changeDetailState = () => {
  MSDSDetailShow.value = false
}
</script>
<style lang="less" scoped>
.Tanks {
  overflow: auto;
  height: 100%;
  overflow: auto;

  .Tanks_Head {
    color: #fff;
    font-weight: bolder;
    font-size: 28px;
    display: flex;
    justify-content: space-between;
    padding: 10px;
    height: 5%;
  }

  .Tanks-top {
    width: 460px;
    height: 330px;

    // background: rgba(1, 10, 15, 0.5);
    .MSDSBox {
      width: 470px !important;
      color: #fff;
      font-size: 20px;
      background: rgb(20, 93, 117);
      position: absolute;
      z-index: 2;
      padding-bottom: 20px;
      font-size: 16px;
      font-weight: bold;

      thead {
        background: black;
        height: 40px;
      }

      .index {
        width: 60px;
        max-width: 60px;
        white-space: nowrap;
      }

      .nameCH {
        width: 100px;
        max-width: 100px;
        white-space: nowrap;
      }

      .nameEN {
        // width: 130px;
        // max-width: 130px;
        white-space: nowrap;
      }

      .indexDES {
        width: 100px;
        max-width: 100px;
        white-space: nowrap;
      }

      tbody {
        tr {
          width: 100%;
          height: 40px;
          border-top: 1px solid #ccc;
          cursor: pointer;

          td {
            overflow: hidden;
          }
        }
      }
    }

    input {
      width: 340px;
      height: 40px;
      padding-left: 10px;
      font-size: 18px;
      background: rgba(0, 255, 204, 0.2);
      border: 1px solid #00ffcc;
      border-radius: 10px;
      color: #fff;
      font-weight: bolder;
    }

    button {
      height: 40px;
      margin-left: 5px;
      padding: 0px 10px;
      background: rgba(0, 255, 204, 1);
      border: 1px solid #00ffcc;
      border-radius: 5px;
    }

    .leftBox {
      width: 40%;
      height: 80%;
      margin-right: 10px;
      padding-top: 20px;

      .left {
        margin-left: 20px;
        margin-top: 20px;
        height: 100%;
        text-align: center;
        font-size: 18px;
        font-weight: bolder;
        color: #00ffff;
        position: relative;

        .box {
          position: relative;

          .centerText {
            font-size: 20px;
            font-weight: bold;
            color: rgba(255, 255, 0, 1);
            position: absolute;
            top: 50%;
            left: 28%;
          }
        }

        .leftText {
          position: absolute;
          top: 30%;
          left: -27px;
        }

        img {
          border: none;
          width: 99px;
          height: 114px;
          margin: auto;
        }
      }
    }

    .rightBox {
      width: 60%;
      height: 100%;
      padding: 10px;

      .formItem {
        width: 100%;
        margin-top: 10px;
        font-size: 14px;

        display: flex;

        .label {
          flex-shrink: 0;
          width: 35%;
          margin-right: 10px;
          color: aqua;
        }

        .content {
          width: 65%;
          color: #fff;
        }

        .activated {
          background: #00ffcc !important;
        }

        .button {
          transform: translateX(14%);
          margin-right: 19%;
          .el-button {
            width: 140px;
            height: 33px;
            border: unset;
            font-size: 22px;
            color: rgba(255, 255, 255, 0.8);
            background-image: url('@/assets/u515.svg');
          }
        }
      }
    }
  }

  .tanks2 {
    width: 460px;
    height: 250px;
  }

  .Tanks-center {
    width: 460px;
    height: 261px;
    background: rgba(1, 10, 15, 0.5);
    padding: 10px;
    margin: 10px 0;

    .Tanks-one-top {
      font-size: 18px;
      display: flex;
      justify-content: space-between;

      img {
        flex-shrink: 0;
        width: 60px;
        height: 60px;
        margin-right: 10px;
      }
    }
  }

  .wxtxText {
    height: 80px !important;
    overflow-y: auto;
  }

  .yhrswText {
    height: 40px !important;
    overflow-y: auto;
  }

  .Tanks-bottom {
    width: 460px;
    height: 150px;
    background: rgba(1, 10, 15, 0.5);
    padding: 10px;
    position: relative;
  }

  .lineBox {
    border: 1px solid red;
    width: 20px;
    height: 55px;
    position: absolute;
    top: 70px;
    left: 210px;
    border-left: 0;
  }

  .line1 {
    width: 20px;
    border: 1px solid red;
    position: absolute;
    left: 230px;
  }

  .line2 {
    width: 50px;
    border: 1px solid red;
    position: absolute;
    left: 200px;
    margin-top: -10px;
  }

  .pjBox {
    width: 200px;
    height: 40px;
    border: 1px solid #00ffcc;
    margin-bottom: 10px;
    padding: 5px;

    span {
      &:nth-of-type(1) {
        color: aqua;
      }
    }
  }

  .title {
    color: aqua;
    flex-shrink: 0;
  }
}
</style>
